/*==========================================================================*\
 |  $Id: Window.java 9 2009-11-06 02:47:13Z VTWoods $
 |*-------------------------------------------------------------------------*|
 |  Copyright (C) 2009 Virginia Tech
 |
 |  This file is part of CloudSpace.
 |
 |  CloudSpace is free software; you can redistribute it and/or modify
 |  it under the terms of the GNU General Public License as published
 |  by the Free Software Foundation; either version 3 of the License, or
 |  (at your option) any later version.
 |
 |  CloudSpace is distributed in the hope that it will be useful,
 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 |  GNU General Public License for more details.
 |
 |  You should have received a copy of the GNU General Public License
 |  along with CloudSpace; if not, see <http://www.gnu.org/licenses/>.
\*==========================================================================*/

package student.web;

import org.zkoss.zk.ui.Component;

//-------------------------------------------------------------------------
/**
 * A generic window.
 *
 * <p>This is a slightly enhanced subclass of {@link org.zkoss.zul.Window}.
 * The main change is that this version provides for a "smart" border
 * property.  An org.zkoss.zul.Window defaults to having no border, all
 * the time.  This subclass defaults to having no border if there is
 * no title or caption, but defaults to including a border if you provide
 * a title or caption.  As always, this is just the default--if you
 * specify a border property yourself, that setting is always respected.
 * </p>
 * <p>See {@link org.zkoss.zul.Window} for the real details on using
 * Windows.</p>
 *
 * @author Stephen Edwards
 * @author Last changed by $Author: VTWoods $
 * @version $Revision: 9 $, $Date: 2009-11-06 02:47:13 +0000 (Fri, 06 Nov 2009) $
 */
public class Window
    extends org.zkoss.zul.Window
{
    //~ Constructors ..........................................................

    // ----------------------------------------------------------
    /**
     * Creates a new Window object.
     */
    public Window()
    {
        super();
    }


    // ----------------------------------------------------------
    /**
     * Creates a new Window object.
     * @param title the window title (see {@link #setTitle}).
     * @param border the border (see {@link #setBorder}).
     * @param closable whether it is closable (see {@link #setClosable}).
     */
    public Window(String title, String border, boolean closable)
    {
        super(title, border, closable);
    }


    //~ Public methods ........................................................

    // ----------------------------------------------------------
    /** Sets the border (either "none" or "normal").
     *
     * @param border the border. If null or "0", "none" is assumed.
     */
    @Override
    public void setBorder( String border )
    {
        hasBorderSetting = true;
        super.setBorder( border );
    }


    // ----------------------------------------------------------
    /**
     * Sets the title.
     * @param title the new title
     */
    @Override
    public void setTitle( String title )
    {
        super.setTitle( title );
        preferToHaveBorder();
    }


    // ----------------------------------------------------------
    /** Inserts a child before the reference child.
     *
     * <p>You could use {@link Component#setParent} or
     * {@link Component#appendChild}
     * instead of this method, unless
     * you want to control where to put the child.
     *
     * @param newChild the new child to be inserted.
     * @param refChild the child before which you want the new child
     * being inserted. If null, the new child is append to the end.
     * @return true if newChild is added successfully or moved;
     * false if it already has the specified child and the order doesn't
     * change.
     */
    @Override
    public boolean insertBefore( Component newChild, Component refChild )
    {
        if (newChild instanceof org.zkoss.zul.Caption)
        {
            preferToHaveBorder();
        }
        return super.insertBefore( newChild, refChild );
    }


    //~ Private methods .......................................................

    // ----------------------------------------------------------
    private void preferToHaveBorder()
    {
        if (!hasBorderSetting)
        {
            setBorder("normal");
        }
    }


    //~ Instance/static variables .............................................

    private transient boolean hasBorderSetting = false;
}
